#! /usr/bin/python
import sys
from TOSSIM import *
from RadioCountMsg import *
#from tinyos.tossim.TossimApp import *

#n = NescApp()
#t = Tossim(n.variables.variables())
t = Tossim([])
m = t.mac();
r = t.radio();

t.addChannel("RadioCountToLedsC", sys.stdout);
t.addChannel("HookReceiverP", sys.stdout);
#t.addChannel("LedsC", sys.stdout);
#t.addChannel("MacLayerSenderP", sys.stdout);
t.addChannel("SCReceiverP", sys.stdout);
#t.addChannel("AuthenticationLayer", sys.stdout);
#t.addChannel("RadioCountToLedsC1", sys.stdout);

for i in range(0, 9):
  m = t.getNode(i);
  m.bootAtTime((31 + t.ticksPerSecond() / 10) * i + 1);

f = open("topo.txt", "r")
lines = f.readlines()
for line in lines:
  s = line.split()
  if (len(s) > 0):
  	r.add(int(s[0]), int(s[1]), float(s[2]))

noise = open("meyer-heavy.txt", "r")
lines = noise.readlines()
for line in lines:
  str = line.strip()
  if (str != ""):
    val = int(str)
    for i in range(0, 9):
      t.getNode(i).addNoiseTraceReading(val)

for i in range (0, 9):
  t.getNode(i).createNoiseModel()

for i in range(0, 50000):
  t.runNextEvent();

for i in range(0, 1000):
  t.runNextEvent();



